#include<iostream>
#include<string.h>
#include<stdio.h>
#include<sys/types.h>
#include<unistd.h>
#include<sys/stat.h>
#include<fcntl.h>

using namespace std;

int main(int argc,char* argv[])
{
  if(argc != 2)
  {
    return 2;
  }
  int fd = open("log.txt", O_WRONLY | O_CREAT | O_APPEND);
  if(fd < 0)
  {
    perror("open");
    return 1;
  }
  //dup2(int old,int new); 
  dup2(fd,1);
  cout << argv[1] << endl;




  //close(1);
  //int fd = open("log.txt",O_RDWR | O_CREAT | O_APPEND, 0666);
  //
  //if(fd < 0)
  //{
  //  perror("open");
  //  return 1;
  //}
  //cout << "hello cout\n" << endl;
  //cout << "hello cout\n" << endl;
  //cout << "hello cout\n" << endl;
  //cout << "hello cout\n" << endl;
  //cout << "hello cout\n" << endl;
  //cout << "hello cout\n" << endl;
  //cout << "hello cout\n" << endl;
  ////printf("hello printf\n");
  //fprintf(stdout,"hello fprintf\n");
  
 // char buffer[64];
 // fgets(buffer,strlen(buffer),stdin);
 // printf("%s\n",buffer);
 //// const char* buff = "hello write\n";
 // write(fd,buff,strlen(buff));
 // char s[64];
 // string str;
 // cout << fd << endl;
 // cout << fd << endl;
 // cout << fd << endl;
 // cout << fd << endl;
 // cout << fd << endl;
 // cout << fd << endl;
 // cout << fd << endl;

 // getline(cin,str);
 // cout << str << endl;
 // //printf("%s\n",s);
  close(fd);
  return 0;
}
